package com.arch.dev.server.bean;

import java.math.BigDecimal;
import java.util.Date;

import javax.persistence.CascadeType;
import javax.persistence.Column;
import javax.persistence.JoinColumn;
import javax.persistence.ManyToOne;

import javax.persistence.Entity;

import javax.persistence.GeneratedValue;

import javax.persistence.Id;

import javax.persistence.Table;

import javax.persistence.Temporal;

import javax.persistence.TemporalType;

import org.hibernate.annotations.ForeignKey;
import org.hibernate.annotations.GenericGenerator;
import org.hibernate.annotations.OnDelete;
import org.hibernate.annotations.OnDeleteAction;

@Entity
@Table(name = "budget")
public class Budget extends AbstractTimestampEntity{

	private Date date;

	private Long id;

	private BigDecimal cost;

	public BigDecimal getCost() {

		return cost;

	}

	@Column(name = "BUDGET_COST")
	public void setCost(BigDecimal cost) {

		this.cost = cost;

	}

	private Catagory catagory;

	@ManyToOne(cascade = { CascadeType.PERSIST, CascadeType.MERGE })
	@JoinColumn(name = "CATAGORY_ID")
	@ForeignKey(name = "FK_CATAGORY_ID")
	@OnDelete(action = OnDeleteAction.CASCADE)
	public Catagory getCatagory() {

		return catagory;

	}

	public void setCatagory(Catagory catagory) {

		this.catagory = catagory;

	}

	public void setId(Long id) {

		this.id = id;

	}

	private String description;

	public Budget() {

	}

	public Budget(String desc, Date date) {

		this.description = desc;

		this.date = date;

	}

	@Temporal(TemporalType.TIMESTAMP)
	@Column(name = "BUDGET_DATE")
	public Date getDate() {

		return date;

	}

	@Id
	@GeneratedValue(generator = "increment")
	@GenericGenerator(name = "increment", strategy = "increment")
	@Column(name = "BUDGET_ID")
	public Long getId() {

		return id;

	}

	@Column(name = "BUDGET_DESCRIPTION")
	public String getDescription() {

		return description;

	}

	public void setDate(Date date) {

		this.date = date;

	}

	public void setDescription(String description) {

		this.description = description;

	}

	@Override
	public String toString() {

		return new String("Id :" + id + "Description : " + description
				+ " Date: " + date);

	}

	public boolean equals(Object obj) {

		Budget budget = (Budget) obj;

		return getId().equals(budget.getId());

	};

}
